const snowId = require("simple-flakeid"),
    JSEncrypt = require("node-jsencrypt"),
    privateKey =
        "MIIBVAIBADANBgkqhkiG9w0BAQEFAASCAT4wggE6AgEAAkEAqhHyZfSsYourNxaY\n" +
        "7Nt+PrgrxkiA50efORdI5U5lsW79MmFnusUA355oaSXcLhu5xxB38SMSyP2KvuKN\n" +
        "PuH3owIDAQABAkAfoiLyL+Z4lf4Myxk6xUDgLaWGximj20CUf+5BKKnlrK+Ed8gA\n" +
        "kM0HqoTt2UZwA5E2MzS4EI2gjfQhz5X28uqxAiEA3wNFxfrCZlSZHb0gn2zDpWow\n" +
        "cSxQAgiCstxGUoOqlW8CIQDDOerGKH5OmCJ4Z21v+F25WaHYPxCFMvwxpcw99Ecv\n" +
        "DQIgIdhDTIqD2jfYjPTY8Jj3EDGPbH2HHuffvflECt3Ek60CIQCFRlCkHpi7hthh\n" +
        "YhovyloRYsM+IS9h/0BzlEAuO0ktMQIgSPT3aFAgJYwKpqRYKlLDVcflZFCKY7u3\n" +
        "UP8iWi1Qw0Y="; // 私钥

class Utils {
    // 成功提示信息
    msgSuccess({ code = 200, message = "success", data }) {
        return {
            code,
            message,
            data,
        };
    }
    //失败提示信息
    msgError({ code = 500, message = "error" }) {
        return {
            code,
            message,
        };
    }
    // 雪花算法生成ID
    getSnowId() {
        let gen1 = new snowId.SnowflakeIdv1({ workerId: 1 });
        return gen1.NextId().toString();
    }
    //解密
    decrypt(val) {
        const encryptor = new JSEncrypt();
        encryptor.setPrivateKey(privateKey);
        return encryptor.decrypt(val);
    }
}

module.exports = new Utils();
